/*
 *  kmeans.h
 *  bgsubtraction
 *
 *  Created by a1gucis on 5/12/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef KMEANS_H
#define KMEANS_H
#define KMEANS_ITERATIONS 100
#include "systeminclude.h"
#include "utils.h"
#include <cstdlib>
#include <time.h>
#include <iostream>
#include <vector>
using namespace std;
class KMeans {
private:
	int K; //number of clusters
	int iterations; //number of iterations kmeans will work
	CvMat *means; //matrix, containing mean values
	CvMat *labels; //matrix, containing labels
	vector<CvMat *> *covMatrices; //vector, containing covariance matrices of each mean
	
	//calculates the covariance matrices
	void calcCovMatrices(IplImage *image);
	
	//calculates the minimum mahalanobis distance from vect to means.
	int minMahalanobisDistance(float chan1, float chan2, float chan3);
	
	//calculates the minimum euclidean distance from vect to means. Input: 1x3 vector. Returns the position of mean vector.
	int minEuclideanDistance(float chan1, float chan2, float chan3);
	
	//recalculates the means values
	void recalcMeans(IplImage *image);
public:
	KMeans(int K);
	void predict(IplImage *sourceImg, IplImage *labelsImg);
};

#endif